package cc.rengu.igas.bomp.core.service.trans;

import cc.rengu.igas.bomp.common.dao.EmvParaInfoMapper;
import cc.rengu.igas.bomp.common.dao.impl.EmvParaInfoMapperImpl;
import cc.rengu.igas.bomp.common.entity.EmvParaInfo;
import cc.rengu.igas.bomp.core.service.base.ManageService;
import cc.rengu.igas.bomp.facade.bean.EmvParamInfoBean;
import cc.rengu.igas.bomp.facade.request.EmvParamInfoQueryRequest;
import cc.rengu.igas.bomp.facade.response.EmvParamInfoQueryResponse;
import cc.rengu.igas.share.common.enums.RespCodeEnum;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.utility.util.ConvertUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * EMV参数查询服务
 * Created by wangcheng on 2021/10/22 13:05
 */
public class EmvParamInfoQueryService extends ManageService {
    @Override
    protected Object bizBeforeCust() throws Exception {
        EmvParamInfoQueryRequest emvParamInfoQueryRequest = new EmvParamInfoQueryRequest();
        ConvertUtil.convertOutput(emvParamInfoQueryRequest);
        return emvParamInfoQueryRequest;
    }

    @Override
    protected BizResponse bizProcessCust(Object request) throws Exception {
        EmvParamInfoQueryRequest emvParamInfoQueryRequest = (EmvParamInfoQueryRequest) request;
        EmvParamInfoQueryResponse emvParamInfoQueryResponse = new EmvParamInfoQueryResponse();
        emvParamInfoQueryResponse.setHeader(emvParamInfoQueryRequest.getHeader());
        EmvParaInfoMapper emvParaInfoMapper = new EmvParaInfoMapperImpl();
        List<EmvParaInfo> emvParaInfoList = emvParaInfoMapper.selectAllEmvParamInfo();
        if (null != emvParaInfoList && !emvParaInfoList.isEmpty()) {
            List<EmvParamInfoBean> emvParamInfoBeans = new ArrayList<>();
            for (EmvParaInfo emvParaInfo : emvParaInfoList) {
                EmvParamInfoBean emvParamInfoBean = new EmvParamInfoBean();
                emvParamInfoBean.setInstId(emvParaInfo.getInstId());
                emvParamInfoBean.setUsageKey(emvParaInfo.getUsageKey());
                emvParamInfoBean.setParamIndex(emvParaInfo.getParaIdx());
                emvParamInfoBean.setParamOrg(emvParaInfo.getParaOrg());
                emvParamInfoBean.setParamId(emvParaInfo.getParaId());
                emvParamInfoBean.setParamStatus(emvParaInfo.getStatus());
                emvParamInfoBean.setParamLength(emvParaInfo.getParaLen());
                emvParamInfoBean.setParamValue(emvParaInfo.getParaVal());
                emvParamInfoBeans.add(emvParamInfoBean);
            }
            emvParamInfoQueryResponse.setEmvParamInfoList(emvParamInfoBeans);
        }

        BizResponse bizResponse = new BizResponse();
        bizResponse.setRspSysId(AppParamConstant.SYS_ID);
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        bizResponse.setResult(emvParamInfoQueryResponse);
        return bizResponse;
    }

    @Override
    protected void bizAfterCust(Object response) throws Exception {
        BizResponse bizResponse = (BizResponse) response;
        EmvParamInfoQueryResponse emvParamInfoQueryResponse = (EmvParamInfoQueryResponse) bizResponse.getResult();
        ConvertUtil.convertInput(emvParamInfoQueryResponse);
    }
}
